home *** CD-ROM | disk | FTP | other *** search
/ Cre@te Online 2000 December / Cre@teOnline CD05.iso / MacSoft / XML ConsoleMax.sea / XML ConsoleMax / Required / esc.jar / com / extensibility / esc / TreeNode.class (.txt) < prev    next >
Encoding:
Java Class File  |  2000-06-30  |  4.0 KB  |  169 lines

  1. package com.extensibility.esc;
  2.  
  3. import java.io.File;
  4. import java.util.Hashtable;
  5. import java.util.Vector;
  6.  
  7. class TreeNode {
  8.    public static final int ROOT = 0;
  9.    public static final int NODE = 1;
  10.    protected int type;
  11.    protected ESCDocument.ESCFile file;
  12.    protected String rootName;
  13.    protected Vector children;
  14.    protected Hashtable hChildren;
  15.    protected TreeNode parent;
  16.  
  17.    public TreeNode(ESCDocument.ESCFile var1, TreeNode var2) {
  18.       this.type = 1;
  19.       this.file = new ESCDocument.ESCFile(File.separator, true);
  20.       this.rootName = "XML Console";
  21.       this.initChildren();
  22.       this.file = var1;
  23.       this.type = 1;
  24.       this.parent = var2;
  25.    }
  26.  
  27.    public TreeNode(String var1) {
  28.       this();
  29.       this.setRootName(var1);
  30.    }
  31.  
  32.    public TreeNode() {
  33.       this.type = 1;
  34.       this.file = new ESCDocument.ESCFile(File.separator, true);
  35.       this.rootName = "XML Console";
  36.       this.initChildren();
  37.       this.type = 0;
  38.       this.parent = null;
  39.    }
  40.  
  41.    public TreeNode(TreeNode var1) {
  42.       this.type = 1;
  43.       this.file = new ESCDocument.ESCFile(File.separator, true);
  44.       this.rootName = "XML Console";
  45.       this.initChildren();
  46.       this.file = var1.file;
  47.       this.type = var1.type;
  48.       this.parent = var1.parent;
  49.    }
  50.  
  51.    public TreeNode getParent() {
  52.       return this.parent;
  53.    }
  54.  
  55.    public void setParent(TreeNode var1) {
  56.       this.parent = var1;
  57.    }
  58.  
  59.    public ESCDocument.ESCFile getFile() {
  60.       return this.file;
  61.    }
  62.  
  63.    public int getType() {
  64.       return this.type;
  65.    }
  66.  
  67.    public void setType(int var1) {
  68.       this.type = var1;
  69.    }
  70.  
  71.    public boolean isRoot() {
  72.       return this.type == 0;
  73.    }
  74.  
  75.    public String getAbsolutePath() {
  76.       return this.isRoot() ? "" : this.file.getAbsolutePath();
  77.    }
  78.  
  79.    public String getID() {
  80.       return this.isRoot() ? this.rootName : this.getAbsolutePath();
  81.    }
  82.  
  83.    public boolean containsChild(TreeNode var1) {
  84.       return this.hChildren.contains(var1);
  85.    }
  86.  
  87.    public boolean containsChild(String var1) {
  88.       return this.hChildren.containsKey(var1);
  89.    }
  90.  
  91.    public TreeNode getChild(String var1) {
  92.       return this.hChildren != null && !this.hChildren.isEmpty() ? (TreeNode)this.hChildren.get(var1) : null;
  93.    }
  94.  
  95.    public TreeNode getChild(int var1) {
  96.       return (TreeNode)this.children.elementAt(var1);
  97.    }
  98.  
  99.    public int getChildIndex(TreeNode var1) {
  100.       return this.children.indexOf(var1);
  101.    }
  102.  
  103.    public synchronized boolean addChild(Object var1) {
  104.       if (var1 instanceof TreeNode) {
  105.          if (this.hChildren == null) {
  106.             this.initChildren();
  107.          }
  108.  
  109.          if (!this.hChildren.contains(var1)) {
  110.             this.hChildren.put(((TreeNode)var1).getID(), var1);
  111.             this.children.addElement(var1);
  112.             return true;
  113.          }
  114.       }
  115.  
  116.       return false;
  117.    }
  118.  
  119.    public synchronized void removeChild(Object var1) {
  120.       if (var1 instanceof TreeNode && this.hChildren != null && this.hChildren.contains(var1)) {
  121.          this.hChildren.remove(((TreeNode)var1).getID());
  122.          this.children.removeElement(var1);
  123.       }
  124.  
  125.    }
  126.  
  127.    public void removeAllChildren() {
  128.       if (this.hChildren != null && this.hChildren.size() > 0) {
  129.          this.initChildren();
  130.       }
  131.  
  132.    }
  133.  
  134.    public int getChildCount() {
  135.       return this.hChildren != null ? this.hChildren.size() : 0;
  136.    }
  137.  
  138.    public boolean isLastFromPath() {
  139.       return this.getChildCount() == 0;
  140.    }
  141.  
  142.    protected Object[] getChildren() {
  143.       TreeNode[] var1 = new TreeNode[this.children.size()];
  144.       this.children.copyInto(var1);
  145.       return var1;
  146.    }
  147.  
  148.    public boolean equals(Object var1) {
  149.       return var1 instanceof TreeNode ? ((TreeNode)var1).getID().equals(this.getID()) : false;
  150.    }
  151.  
  152.    public String toString() {
  153.       return this.isRoot() ? this.rootName : this.file.getName();
  154.    }
  155.  
  156.    public String getRootName() {
  157.       return this.rootName;
  158.    }
  159.  
  160.    public void setRootName(String var1) {
  161.       this.rootName = var1;
  162.    }
  163.  
  164.    private void initChildren() {
  165.       this.hChildren = new Hashtable();
  166.       this.children = new Vector(5);
  167.    }
  168. }
  169.